class Solution(object):
    def hIndex(self, citations):
        """
        :type citations: List[int]
        :rtype: int
        """
        n = len(citations)
        right_index = len(citations) - 1
        left_index = 0
        while left_index < right_index:
            mid_index = (left_index + right_index) // 2
            if citations[mid_index] >= n - mid_index:
                right_index = mid_index
            else:
                left_index = mid_index + 1

        if citations[left_index] >= n - left_index:
            return n - left_index
        else:
            return 0


data = Solution()
citations = [0, 1, 3, 5, 6]
print(data.hIndex(citations))
